package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author gax
 * @since 2025-08-23
 */
@RestController
@RequestMapping("/categoryBrand")
@Tag(name = "分类-品牌中间表的类")
public class CategoryBrandController extends BaseController {
    @Autowired
    private ICategoryBrandService categoryBrandService;

    @Operation(summary = "分页查询分类-品牌列表")
    @GetMapping("list")
    public TableDataInfo list() {
        startPage();
        List<CategoryBrand> list = categoryBrandService.selectCategoryBrandList();
        return getDataTable(list);
    }

    @Operation(summary = "新增加分类-品牌关系")
    @PostMapping
    public AjaxResult saveCategoryBrand(@RequestBody CategoryBrand categoryBrand) {
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(categoryBrandService.insertCategoryBrand(categoryBrand));
    }

    @Operation(summary = "批量删除分类-品牌关系")
    @DeleteMapping("{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids) {
        categoryBrandService.removeByIds(ids);
        return AjaxResult.success();
    }

    @Operation(summary = "根据分类id获取品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult selectBrandListByCategoryId(
            @Parameter(description = "分类id")
            @PathVariable Long categoryId) {
        List<Brand> list = categoryBrandService.selectBrandListByCategoryId(categoryId);
        return success(list);
    }
}
